package com.notary.tx_live_plugin;

import android.content.Context;
import android.util.Log;

import com.notary.tx_live_plugin.platform.ChatMeetPlatformView;
import com.notary.tx_live_plugin.util.FlavorConfig;
import com.notary.tx_live_plugin.util.TxLogger;
import com.tencent.rtmp.TXLiveBase;

import java.util.HashMap;

import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.platform.PlatformView;

/**
 * flavor为txLive的配置类
 * flavor为txLivePro是专业版的直播推流 配置
 */
public class FlavorConfigImpl extends FlavorConfig {

    private static final class FlavorConfigHolder{
        private static final FlavorConfigImpl instance = new FlavorConfigImpl();
    }
    
    public static FlavorConfig getInstance(){
        return FlavorConfigHolder.instance;
    }
    
    private FlavorConfigImpl(){}


    /**
     * flavor为txLive的初始化application
     */
    public boolean initApplication(Context context, HashMap<String,Object> params){
        if(context == null) {
            Log.d("txLivePlugin","专业版使用直播推流，出现context为空");
            return false;
        }
        TxLogger.d("getPackageName",context.getPackageName());
        //设置license
        String licenceURL = params == null ? null : (String) params.get("licenseURL");
        String licenceKey = params == null ? null : (String) params.get("licenceKey");
        if(licenceKey == null || licenceURL == null){
            //专业版使用直播推流，需要获取licence，出现参数key或url为空导致无法获取
            Log.d("txLivePlugin","专业版使用直播推流，需要获取licence，出现参数key或url为空导致无法获取 " +
                    "txLivePro licence params is null, licenceKey "+licenceKey+" licenceURL "+licenceURL);
            return false;
        }
        TXLiveBase.getInstance().setLicence(context, licenceURL, licenceKey);
        return true;
    }

    public PlatformView getChatView(BinaryMessenger binaryMessenger, Context context, int viewId, HashMap<String, Object> params){
        return new ChatMeetPlatformView(binaryMessenger,context,viewId,params);
    }
}
